package com.itheima.jobs;

import com.itheima.constant.RedisConstant;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.util.CollectionUtils;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * @author Autism
 * @version V1.0
 * @Package com.itheima.jobs
 * @date 2019/7/29 16:30
 * @Description
 */
public class ClearJob {
    @Autowired
    JedisPool jedisPool;


    public void clearImg(){
    //找到垃圾图片
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if (!CollectionUtils.isEmpty(sdiff)) {
            sdiff.forEach(item->{
                //清理七牛云垃圾信息
                QiniuUtils.deleteFileFromQiniu(item);
                //清理redis垃圾信息
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_DB_RESOURCES, item);
                System.out.println("删除图片:" + item);
            });

        }
    }

    public static void main(String[] args) {
        System.out.println(new BCryptPasswordEncoder().encode("1234"));
    }

}
